package com.example.flyWeightPattern.factory;

import com.example.flyWeightPattern.shape.Circle;
import com.example.flyWeightPattern.shape.Shape;

import java.util.HashMap;

/**
 * 模型工厂
 * sun 2017-12-18.
 */
public class ShapeFactory {

    private static final HashMap<String,Shape> circleMap = new HashMap<>();
    public static Shape getCircle(String color){
        Circle circle =  (Circle) circleMap.get(color);
        if(circle == null){
            circle = new Circle(color);
            circleMap.put(color,circle);
            System.out.println("Creating circle of color = [" + color + "]");
        }
        return circle;
    }
}
